home *** CD-ROM | disk | FTP | other *** search
- class TakFlying extends Library.State
- {
- var bGoingLeft;
- var bGoingRight;
- var oKeysManager;
- var nFollowY;
- var nSpeedX;
- var nSpeedY;
- var bFlyingDown;
- var oFlappingSound;
- var mcRef;
- var nLeftLimit;
- var nRightLimit;
- var nSpeedXMaxModifier;
- var nSpeedYMaxModifier;
- var sState;
- static var oCtrl;
- static var UP_LEFT_LIMIT = 50;
- static var UP_RIGHT_LIMIT = 550;
- static var DOWN_LEFT_LIMIT = 50;
- static var DOWN_RIGHT_LIMIT = 550;
- static var START_SPEED = 60;
- static var SPEED_LOOSE = 0.35;
- static var GRAVITY_GAIN = 0.85;
- static var MAX_DROP_SPEED = 20;
- static var MAX_SPEED_AIR = 8;
- static var ACCELERATION_AIR = 0.75;
- static var DIRECTION_CHANGE_FACTOR_AIR = 0.85;
- function TakFlying(__mcRef)
- {
- super(__mcRef);
- this.bGoingLeft = false;
- this.bGoingRight = false;
- this.oKeysManager = new Library.Utils.KeysManager();
- this.oKeysManager.setListenerForKey(this,38);
- this.oKeysManager.setListenerForKey(this,40);
- this.oKeysManager.setListenerForKey(this,37);
- this.oKeysManager.setListenerForKey(this,39);
- this.nFollowY = -50;
- this.nSpeedX = 0;
- this.nSpeedY = - TakFlying.START_SPEED;
- this.setState("FlyUp");
- MiniGameManager.Instance.doAddListener(this);
- }
- static function get Instance()
- {
- return TakFlying.oCtrl;
- }
- function onKeyManagerEvent(__nEvent, __nCode)
- {
- if(!this.Paused)
- {
- switch(__nEvent)
- {
- case Library.Utils.KeysManager.EVENT_KEY_DOWN:
- switch(__nCode)
- {
- case 37:
- this.bGoingLeft = true;
- break;
- case 39:
- this.bGoingRight = true;
- break;
- case 38:
- if(this.bFlyingDown)
- {
- this.setState("FlyDownSlow");
- }
- break;
- case 40:
- if(this.bFlyingDown)
- {
- this.setState("FlyDownFast");
- }
- }
- break;
- case Library.Utils.KeysManager.EVENT_KEY_UP:
- switch(__nCode)
- {
- case 37:
- this.bGoingLeft = false;
- break;
- case 39:
- this.bGoingRight = false;
- break;
- case 38:
- if(this.bFlyingDown)
- {
- if(this.oKeysManager.isKeyDown(40))
- {
- this.setState("FlyDownFast");
- }
- else
- {
- this.setState("FlyDown");
- }
- }
- break;
- case 40:
- if(this.bFlyingDown)
- {
- if(this.oKeysManager.isKeyDown(38))
- {
- this.setState("FlyDownSlow");
- }
- else
- {
- this.setState("FlyDown");
- }
- }
- }
- }
- }
- }
- function doSoundEvent(__nEvent, __oSound)
- {
- if(__nEvent === Library.Sound.SoundManager.EVENT_SOUND_COMPLETE)
- {
- if(__oSound == this.oFlappingSound)
- {
- delete this.oFlappingSound;
- }
- }
- }
- function doPause()
- {
- super.doPause();
- this.oFlappingSound.doPause();
- }
- function doResume()
- {
- super.doResume();
- this.oFlappingSound.doResume();
- }
- function doDestroy()
- {
- this.oKeysManager.doDestroy();
- delete this.oKeysManager;
- delete TakFlying.oCtrl;
- MiniGameManager.Instance.doRemoveListener(this);
- this.oFlappingSound.doDestroy();
- delete this.oFlappingSound;
- }
- function get FollowY()
- {
- return this.nFollowY;
- }
- function get Ref()
- {
- return this.mcRef;
- }
- function doFlyUp()
- {
- this.doMoveY();
- this.nLeftLimit = TakFlying.UP_LEFT_LIMIT;
- this.nRightLimit = TakFlying.UP_RIGHT_LIMIT;
- this.nSpeedXMaxModifier = -2;
- this.doMoveX();
- this.bFlyingDown = false;
- if(this.nSpeedY >= -2)
- {
- this.setState("FlyChange");
- }
- }
- function doFlyChange()
- {
- this.doMoveY();
- this.doMoveX();
- if(this.isStateComplete())
- {
- if(this.oKeysManager.isKeyDown(40))
- {
- this.setState("FlyDownFast");
- }
- else if(this.oKeysManager.isKeyDown(38))
- {
- this.setState("FlyDownSlow");
- }
- else
- {
- this.setState("FlyDown");
- }
- }
- }
- function doFlyDownSlow()
- {
- this.nSpeedYMaxModifier = -10;
- this.nSpeedY = Library.Utils.MoreMath.getReachNum(this.nSpeedY,TakFlying.MAX_DROP_SPEED + this.nSpeedYMaxModifier,1.5);
- this.doFall();
- }
- function doFlyDownFast()
- {
- this.nSpeedYMaxModifier = 50;
- this.nSpeedY = Library.Utils.MoreMath.getReachNum(this.nSpeedY,TakFlying.MAX_DROP_SPEED + this.nSpeedYMaxModifier,2.5);
- this.doFall();
- }
- function doFlyDown()
- {
- this.nSpeedYMaxModifier = 0;
- this.doFall();
- }
- function doFall()
- {
- this.doMoveY();
- this.nLeftLimit = TakFlying.DOWN_LEFT_LIMIT;
- this.nRightLimit = TakFlying.DOWN_RIGHT_LIMIT;
- this.nSpeedXMaxModifier = 0;
- this.doMoveX();
- this.bFlyingDown = true;
- }
- function doMoveY()
- {
- if(this.nSpeedY < 0)
- {
- this.nSpeedY += TakFlying.SPEED_LOOSE;
- }
- else
- {
- this.nSpeedY += TakFlying.GRAVITY_GAIN;
- if(this.nFollowY <= -230)
- {
- this.nFollowY = -230;
- }
- else
- {
- this.nFollowY -= 5;
- }
- }
- if(this.nSpeedY > TakFlying.MAX_DROP_SPEED + this.nSpeedYMaxModifier)
- {
- this.nSpeedY = Library.Utils.MoreMath.getReachNum(this.nSpeedY,TakFlying.MAX_DROP_SPEED + this.nSpeedYMaxModifier,0.5);
- }
- if(this.mcRef._y + this.nSpeedY < 0)
- {
- this.mcRef._y += this.nSpeedY;
- }
- else
- {
- this.setState("FlyDown");
- this.doLockState();
- this.mcRef._y += this.nSpeedY;
- MiniGameManager.Instance.doMinigameEnd();
- }
- }
- function doMoveX()
- {
- if(this.bGoingRight)
- {
- if(this.nSpeedX < 0)
- {
- this.nSpeedX *= TakFlying.DIRECTION_CHANGE_FACTOR_AIR;
- }
- if(this.nSpeedX < TakFlying.MAX_SPEED_AIR + this.nSpeedXMaxModifier)
- {
- this.nSpeedX += TakFlying.ACCELERATION_AIR;
- }
- }
- else if(this.bGoingLeft)
- {
- if(this.nSpeedX > 0)
- {
- this.nSpeedX *= TakFlying.DIRECTION_CHANGE_FACTOR_AIR;
- }
- if(this.nSpeedX > - (TakFlying.MAX_SPEED_AIR + this.nSpeedXMaxModifier))
- {
- this.nSpeedX -= TakFlying.ACCELERATION_AIR;
- }
- }
- else
- {
- this.nSpeedX = Library.Utils.MoreMath.getReachZero(this.nSpeedX,TakFlying.ACCELERATION_AIR);
- }
- if(this.mcRef._x + this.nSpeedX > this.nLeftLimit && this.mcRef._x + this.nSpeedX < this.nRightLimit)
- {
- this.mcRef._x += this.nSpeedX;
- }
- else
- {
- this.nSpeedX = 0;
- }
- }
- function doLoadStateAction()
- {
- super.doLoadStateAction();
- switch(this.sState)
- {
- case "FlyChange":
- MiniGameManager.Instance.doStopWinds();
- break;
- case "FlyDown":
- MiniGameManager.Instance.doStartWindNormal();
- if(this.oFlappingSound != undefined)
- {
- this.oFlappingSound.setFadeRate(15);
- this.oFlappingSound.doFadeTo(0);
- }
- break;
- case "FlyDownFast":
- MiniGameManager.Instance.doStartWindFast();
- if(this.oFlappingSound != undefined)
- {
- this.oFlappingSound.setFadeRate(15);
- this.oFlappingSound.doFadeTo(0);
- }
- break;
- case "FlyDownSlow":
- MiniGameManager.Instance.doStartWindSlow();
- if(this.oFlappingSound == undefined)
- {
- this.oFlappingSound = Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"SkySlow.wav",10,999);
- this.oFlappingSound.doAddListener(this);
- }
- this.oFlappingSound.doFadeTo(60);
- }
- }
- }
-